package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.AllBean;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/13 19:12
 */

public class MyGridAdapter2 extends BaseAdapter implements View.OnClickListener {
    private Context mContext;
    private List<AllBean.DataBean.ActivityBean>mAllBeen;
    private MyRecyclerViewAdapter mAdapter;

    public MyGridAdapter2(Context context, List<AllBean.DataBean.ActivityBean> allBeen) {
        mContext = context;
        mAllBeen = allBeen;
    }

    @Override
    public int getCount() {
        return mAllBeen==null?0:mAllBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return mAllBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        convertView=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(mContext).inflate(R.layout.item_adapter,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(mAllBeen.get(position).url).into(viewHolder.iv);
        viewHolder.iv.setOnClickListener(this);
        viewHolder.mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL,false));
        mAdapter=new MyRecyclerViewAdapter(mContext,mAllBeen.get(position).goods);
        viewHolder.mRecyclerView.setAdapter(mAdapter);
        return convertView;
    }

    @Override
    public void onClick(View v) {
        Toast.makeText(mContext, "您点击了", Toast.LENGTH_SHORT).show();
    }

    private static class ViewHolder{
        private ImageView iv;
        private RecyclerView mRecyclerView;
        public ViewHolder(View view){
            iv= (ImageView) view.findViewById(R.id.item_adapter_iv);
            mRecyclerView= (RecyclerView) view.findViewById(R.id.item_adapter_RecyclerView);
        }
    }
}
